﻿using Biz.Check;
using Biz.Status;
using Biz.Treat;
using Biz.Utility;
using DataLogical.TableClass;


namespace Biz
{
    public class TreatApplication : Application
    {
        private string restaurant;

        public string Restaurant
        {
            get { return restaurant; }
            set { restaurant = value; }
        }
        private string telephone;

        public string Telephone
        {
            get { return telephone; }
            set { telephone = value; }
        }
        private string address;

        public string Address
        {
            get { return address; }
            set { address = value; }
        }
        private string intention;

        public string Intention
        {
            get { return intention; }
            set { intention = value; }
        }
        public new int NumOfPerson
        {
            get { return TreatContent.NumberOfUs; }
        }

        public new decimal AverageAmount
        {
            get { return TreatContent.AverageAmount; }
        }

        public new decimal TotalAmount
        {
            get { return TreatContent.TotalAmount; }
        }

        public new decimal ActualFee
        {
            get { return TreatContent.ActualFee; }
        }
        private TreatContent treatContent;

        public TreatContent TreatContent
        {
            get { return treatContent; }
            set { treatContent = value; }
        }
        private tblApplicationTreat application = new tblApplicationTreat();


        public override void save()
        {
            application.Applicant = ApplicantID.Value;
            application.Approver = ApproverID;
            application.GaUser = GaUser;
            application.ExcuteDate = ExcuteDate;
            application.Opposite = Opposite;
            application.CheckListType = CheckList.PRODUCT_NAME;
            CheckList.save();
            application.CheckListID = CheckList.Id;
            Status.save();
            application.Status = Status.PRODUCT_NAME;
            application.Remarks = Remarks;
            application.Intention = Intention;
            TreatContent.NumOfPerson = NumOfPerson;
            TreatContent.AverageAmount = AverageAmount;
            TreatContent.TotalAmount = TotalAmount;
            TreatContent.ActualFee = ActualFee;
            TreatContent.save();
            application.TreatContentID = TreatContent.Id;
            application.TreatContentType = TreatContent.PRODUCT_NAME;
            application.Restaurant = Restaurant;
            application.Telephone = Telephone;
            application.Address = Address;
            application.Intention = Intention;
            if (Id == Define.NEW)
                Id = application.Insert(application);
            else
                application.Update(application);
        }

        public override void load(int _id)
        {
            application = new tblApplicationTreat(_id);
            Id = application.ID;
            ApplicantID = application.Applicant;
            ApproverID = application.Approver;
            GaUser = application.GaUser;
            ExcuteDate = application.ExcuteDate.Value;
            Opposite = application.Opposite;
            CheckList = (CheckList)Factory.Factory.getInstance().CreateProduct(application.CheckListType);
            CheckList.load(application.CheckListID.Value);
            Status = (ApplicationStatus)Factory.Factory.getInstance().CreateProduct(application.Status);
            Remarks = application.Remarks;
            Restaurant = application.Restaurant;
            Telephone = application.Telephone;
            Address = application.Address;
            Intention = application.Intention;
            TreatContent = (TreatContent)Factory.Factory.getInstance().CreateProduct(application.TreatContentType);
            TreatContent.load(application.TreatContentID.Value);
        }

        public override string PRODUCT_NAME
        {
            get { return ApplicationType.TREAT.ToString(); }
        }
    }
}
